Skip to content

feat: Add AddNameToNullArgumentRector#8000

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
calebdw:calebdw/push-vsxxtuwkpklt
May 21, 2026
Merged

feat: Add AddNameToNullArgumentRector#8000
TomasVotruba merged 1 commit into
rectorphp:mainfrom
calebdw:calebdw/push-vsxxtuwkpklt

Conversation

@calebdw
Copy link
Copy Markdown
Contributor

@calebdw calebdw commented May 21, 2026

Hello!

This is similar to #7944 but for null arguments. I refactored the core logic into a reusable service so that other rules can be easily added in the future

Thanks!

@TomasVotruba TomasVotruba merged commit 749a175 into rectorphp:main May 21, 2026
62 checks passed
@TomasVotruba
Copy link
Copy Markdown
Member

Looks good, thank you

@calebdw calebdw deleted the calebdw/push-vsxxtuwkpklt branch May 21, 2026 12:01
@u01jmg3
Copy link
Copy Markdown
Contributor

u01jmg3 commented May 27, 2026

Nice addition - is there a way of removing unnecessary parameters (because it's the default value) once a named argument has been introduced?

e.g.

This Rector made this change:

-$table->addRow(null, $styles['cant-split']);
+$table->addRow(height: null, style: $styles['cant-split']);

But we can go further:

-$table->addRow(height: null, style: $styles['cant-split']);
+$table->addRow(style: $styles['cant-split']);

(Ref: https://github.com/PHPOffice/PHPWord/blob/master/src/PhpWord/Element/Table.php#L67)

@samsonasik
Copy link
Copy Markdown
Member

samsonasik commented May 27, 2026

@u01jmg3 there is RemoveNullArgOnNullDefaultParamRector rule for that, activate deadCode set will combine 2 rules: SortCallLikeNamedArgsRector + RemoveNullArgOnNullDefaultParamRector see

https://getrector.com/demo/8186634c-2eb5-411d-8709-0f9d508924ab

You can configure:

<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPreparedSets(codeQuality: true, deadCode: true);

@u01jmg3
Copy link
Copy Markdown
Contributor

u01jmg3 commented May 27, 2026

It looks like Rector (or PHPStan) is not able to infer this from PHPWord...

@TomasVotruba
Copy link
Copy Markdown
Member

@u01jmg3 Looks doable.
Can you create a new issue and provide 2 examples with both code and class as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants